// 解析交通信息
export function parseTravelTypes(traffic) {
  const travelTypes = [];
  const tt = traffic.split('>');
  if (tt.length > 1) {
    for (let j = 0; j < tt.length; j++) {
      if (j === 0) {
        travelTypes.push({
          Type: '',
          TreeName: tt[j]
        });
      } else {
        const places = tt[j].split(':');
        travelTypes.push({
          Type: places[0],
          TreeName: places[1]
        });
      }
    }
  } else {
    travelTypes.push({
      Type: '',
      TreeName: tt[0]
    });
  }
  return travelTypes;
}

// 解析图片信息
export function parseTravelPhotos(photos) {
  const travelPhotos = [];
  if (photos && photos.length) {
    for (const photo of photos) {
      travelPhotos.push({ ImgUrl: this.$config.staticDomainURL + '/' + photo.realpath });
    }
  }
  return travelPhotos;
}

// 解析景点信息
export function parseViewspots(viewspot) {
  const viewspots = [];
  if (viewspot && viewspot.length > 0) {
    const spots = viewspot.split(' ');
    for (const spot of spots) {
      if (spot !== 'null' && spot !== '') {
        viewspots.push({ name: spot });
      }
    }
  }
  return viewspots;
}

/**
 * 提取用餐信息处理逻辑到单独的函数
 * @param {Object} Detail 每日行程详情
 * @returns {Array} 用餐信息数组
 */
export function parsetLunchInfo (Detail) {
  const Lunch = [];
  const meals = ['Breakfast', 'HaveLunch', 'Dinner'];
  const mealNames = ['早', '中', '晚'];

  meals.forEach((meal, index) => {
    const type = Detail[meal] === '1' ? 'right' : 'close';
    Lunch.push({
      Type: type,
      Name: mealNames[index],
    });
  });

  return Lunch;
}
